package com.ruoyi.match.exception;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel(value = "CustomResponse", description = "返回数据结构定义")
@Data
public class CustomResponse {
	@ApiModelProperty(dataType = "int",value="状态码",example = "200-400-500")
	private int code;
	@ApiModelProperty(dataType = "String",value="响应信息",example = "success等")
	private String message;
	@ApiModelProperty(dataType = "Object",value="响应数据")
	private Object data;

	private CustomResponse() {
	}

	public static CustomResponse error(CustomExceptionType customExceptionType) {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(customExceptionType.getCode());
		resultBean.setMessage(customExceptionType.getTypeDesc());


		return resultBean;
	}
	// 请求出现异常时的响应数据封装
	public static CustomResponse error(CustomException e) {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(e.getResultJson().code);
		resultBean.setMessage(e.getResultJson().message);
		resultBean.setData(e.getResultJson().getData());

		return resultBean;
	}
	public static CustomResponse error(CustomException e, String s1) {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(e.getCode());
		resultBean.setMessage(e.getMessage());
		resultBean.setData(e.getResultJson());

		return resultBean;
	}
	// 请求出现异常时的响应数据封装
	public static CustomResponse error(CustomExceptionType customExceptionType, String errorMessage) {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(customExceptionType.getCode());
		resultBean.setMessage(customExceptionType.getTypeDesc());
		resultBean.setData(errorMessage);
		return resultBean;
	}

	// 请求处理成功时的数据响应
	public static CustomResponse success() {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(200);
		resultBean.setMessage("success");
		return resultBean;
	}
	public static CustomResponse succ(String msg) {
		CustomResponse resultBean = new CustomResponse();
		resultBean.setCode(200);
		resultBean.setMessage(msg);
		return resultBean;
	}
	// 请求处理成功，并响应结果数据
	public static CustomResponse success(Object data) {
		CustomResponse resultBean = CustomResponse.success();
		resultBean.setData(data);
		return resultBean;
	}
	@Override
	public String toString() {
		return "{" +
				"\"code\":" + code +
				", \"msg\":\"" + message + '\"' +
				", \"data\":\"" + data + '\"'+
				'}';
	}
}
